<?php
require_once("koneksi.php");

$nama_anggota = ''; 
$username = ''; 
$email = ''; 
$pass = ''; 
$kontak = ''; 
if (isset($_POST['nama_anggota']))
$nama_anggota = $_POST['nama_anggota'];
if (isset($_POST['username']))
$username = $_POST['username'];
if (isset($_POST['email']))
$email = $_POST['email'];
if (isset($_POST['password']))
$pass = $_POST['password'];
if (isset($_POST['kontak']))
$kontak = $_POST['kontak'];
$cekuser = mysql_query("SELECT * FROM anggota WHERE username = '$username'");

if(mysql_num_rows($cekuser) <> 0) 
	{
		echo "Username Sudah Terdaftar!<br/>";
		echo "<a href='daftar.php'>Back</a>";
	}
else 
	{
		if(!$username || !$pass) 
		{
			echo ("<SCRIPT LANGUAGE='JavaScript'>
        	window.alert('Failed! Harus di isi semua fieldnya..')
        	window.location.href='index.php?page=daftar'
        	</SCRIPT>"); 
		} 
		else 
		{
			$simpan = mysql_query("INSERT INTO anggota(nama_anggota, username, email, password, kontak) VALUES('$nama_anggota','$username','$email','$pass','$kontak')");
			if($simpan) 
			{
				header ('location:index.php?page=daftar');
			} 
			else 
			{
				echo "Proses Gagal!";
		}
	}
}
?>